﻿using System;
using System.Windows.Input;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.ServiceLocation;

using Acceron.Univerisy.Modules.Scheduling.ViewModels;
using Acceron.Univeristy.Common;

namespace Acceron.Univerisy.Modules.Scheduling.Commands
{
    public class SaveScheduleCommand : ICommand
    {
        ScheduleViewModel _viewModel;

        readonly Predicate<object> _canExecute;

        public SaveScheduleCommand(ScheduleViewModel viewModel)
            : this(viewModel, null)
        {
        }

        public SaveScheduleCommand(ScheduleViewModel viewModel, Predicate<object> canExecute)
        {
            _viewModel = viewModel;
            _canExecute = canExecute;
        }


        public bool CanExecute(object parameter)
        {
            return _canExecute == null ? true : _canExecute(parameter);
        }

        public event EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }

        public void Execute(object parameter)
        {
            var eventAggregator = ServiceLocator.Current.GetInstance<IEventAggregator>();
            var clieckedEvent = eventAggregator.GetEvent<ButtonClickedEvent>();
            clieckedEvent.Publish("SaveSchedule");
        }
    }
}
